package com.javase.多线程.interrupt线程中断和通信;

import java.util.concurrent.TimeUnit;

/**
 * @Auther: liyanhao
 * @Description: Interrupt线程中断
 * @Date: 2022/5/15 09:21
 * @Version: v1.0
 */
public class InterruptMainTest {
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            while (!Thread.currentThread().isInterrupted()){
                System.out.println("我在执行");
            }
        });
        t1.start();

        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(5);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            t1.interrupt();
        }).start();
    }

}
